/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.commonsio;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.io.IOException;

/**
 * <p>Project: app2022 - CommonsIo1
 * <p>Powered by webrx On 2022-01-20 16:28:34
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class CommonsIo1 {
    public static void main(String[] args) throws IOException {
        //删除文件
        //FileUtils.delete(new File("p10_40(180_120).jpg"));
        //FileUtils.deleteDirectory(new File("c:\\abc4"));

        //apache commons io 工具类实现目录的复制
        FileUtils.copyDirectory(new File("c:\\abc5"), new File("c:\\ddd6"));

        //目录操作
        String s = FileUtils.getUserDirectoryPath();
        System.out.println(s);
        System.out.println(System.getProperty("user.home"));

        FileUtils.createParentDirectories(new File("c:\\acc\\yy\\xxx"));

        //建立文件
        //FileUtils.write(new File("xy.txt"), "hello world 中文\n", "utf-8", true);
        //读取 文件
        String txt = FileUtils.readFileToString(new File("xy.txt"), "utf-8");
        System.out.println(txt);
        String fn = "c:\\app2022\\p.jpg";
        System.out.println(FilenameUtils.getExtension(fn));
        System.out.println(FilenameUtils.getName(fn));
        System.out.println(FilenameUtils.getBaseName(fn));
        System.out.println(FilenameUtils.getFullPathNoEndSeparator(fn));


    }
}
